/**
 * Created by tanbingqin on 2020/11/27.
 */
import React from "react";
import moment from "moment";
import { message, Row } from "antd";
import { messages } from "share/common";
import Condition from "components/condition";
const If = Condition.If;
import requestUtil from "containers/request/slide/request-util";

export default {
  travelCarRender(field, formInfo) {
    let carTypeMapReverse = {
      1: "travel",
      3: "date",
      2: "times",
      4: "carQuick",
      5: "carPickup",
      6: "aliCar",
    };
    let showValue = field.showValue ? JSON.parse(field.showValue) : {};
    let showList = [];
    //用车类型
    showList.push({
      name: messages("request-1.key499") /*用车类型*/,
      showValue: this.getDiDiType(showValue.approvalType),
    });
    //用车制度
    if (
      [1, 2, 3].indexOf(showValue.approvalType) > -1 &&
      requestUtil.isCarField(field, carTypeMapReverse[showValue.approvalType], "carRule", "show")
    ) {
      showList.push({
        name: messages("request-1.key500") /*用车制度*/,
        showValue: showValue.regulationName,
      });
    }
    //日期
    if (requestUtil.isCarField(field, carTypeMapReverse[showValue.approvalType], "startEndDate", "show")) {
      showList.push({
        name: messages("request-1.key898") /*开始日期-结束日期*/,
        showValue: `${moment(showValue.startDate).format("YYYY-MM-DD")} ~ ${moment(showValue.endDate).format(
          "YYYY-MM-DD"
        )}`,
      });
    }
    //出发城市 差旅用车，阿里用车
    if (
      [1, 6].indexOf(showValue.approvalType) > -1 &&
      requestUtil.isCarField(field, carTypeMapReverse[showValue.approvalType], "fromCity", "show")
    ) {
      showList.push({
        name: messages("request-1.key556") /*出发城市*/,
        showValue: showValue.departureCity,
      });
    }
    //到达城市 差旅用车，阿里用车
    if (
      [1, 6].indexOf(showValue.approvalType) > -1 &&
      requestUtil.isCarField(field, carTypeMapReverse[showValue.approvalType], "toCity", "show")
    ) {
      showList.push({
        name: messages("request-1.key613") /*到达城市*/,
        showValue: showValue.destinationCity,
      });
    }
    //城市 按日期用车，马上用车，接送车
    if (
      [2, 4, 5].indexOf(showValue.approvalType) > -1 &&
      requestUtil.isCarField(field, carTypeMapReverse[showValue.approvalType], "city", "show")
    ) {
      showList.push({
        name: messages("request-1.key663") /*城市*/,
        showValue: showValue.destinationCity,
      });
    }
    //次数 按次用车、马上用车
    if (
      [2, 4].indexOf(showValue.approvalType) > -1 &&
      requestUtil.isCarField(field, carTypeMapReverse[showValue.approvalType], "useTimes", "show")
    ) {
      showList.push({
        name: messages("request-1.key503") /*用车次数*/,
        showValue: typeof showValue.tripTimes === "number" ? showValue.tripTimes + "" : "",
      });
    }
    //标准 按日期用车、马上用车
    if (
      [3, 4].indexOf(showValue.approvalType) > -1 &&
      requestUtil.isCarField(field, carTypeMapReverse[showValue.approvalType], "carStandard", "show")
    ) {
      let amountStr = "";
      if (showValue.tripAmount || showValue.tripAmount === 0) {
        amountStr = React.Component.prototype.filterMoney(showValue.tripAmount, 2, true);
      }
      showList.push({
        name: messages("request-1.key899") /*标准*/,
        showValue: amountStr,
      });
    }
    //接送类型
    if (
      showValue.approvalType === 5 &&
      requestUtil.isCarField(field, carTypeMapReverse[showValue.approvalType], "type", "show")
    ) {
      showList.push({
        name: messages("request-1.key499") /*用车类型*/,
        showValue: showValue.carPickUpTypeDescription,
      });
    }

    return (
      <div>
        {showList.map((item) => {
          return (
            <Row style={{ marginBottom: 12, lineHeight: "31px" }} type="flex" align="top">
              <span
                style={{
                  display: "inline-block",
                  width: "140px",
                  marginRight: 12,
                }}
              >
                {item.messageKey !== "com_prompt_text" && (
                  <span>
                    {item.name}
                    {item.name && " : "}
                  </span>
                )}
              </span>
              <span
                style={{
                  display: "inline-block",
                  width: "calc(100% - 152px)",
                }}
              >
                {item.showValue || "-"}
              </span>
            </Row>
          );
        })}
      </div>
    );
  },

  getDiDiType(approvalType) {
    if (approvalType === 1) {
      return messages("request-1.key469") /*差旅用车*/;
    }
    if (approvalType === 2) {
      return messages("request-1.key470") /*按次数用车*/;
    }
    if (approvalType === 3) {
      return messages("request-1.key471") /*按日期用车*/;
    }
    if (approvalType === 4) {
      return messages("request-1.key472") /*马上用车*/;
    }
    if (approvalType === 5) {
      return messages("request-1.key473") /*接送机／火车*/;
    }
    if (approvalType === 6) {
      return messages("request-1.key923") /*阿里用车*/;
    }
    return null;
  },
};
